var number = 8;
var number_1 = 5;
var startingPage;
//展示最新出现的8种废品
//废品初始数据
function loadWebList() {
    startingPage = 0;
    var data = {
        "page": startingPage,
        "number": number
    };
    $.ajax({
        url: "findWebRecycleProductByRecycleProductList",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(data),
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            var code = ' ';
            if (data.code == 500) {
                Swal.fire("提示", "查询数据失败", "error");
            } else {
                for (var i = 0; i < data.product_List.length; i++) {
                    code += "<div class=\"col-lg-3 col-md-4 col-sm-6\">\n" +
                        "                    <div class=\"product-box-layout1\">\n" +
                        "                        <div class=\"item-img\">\n" +
                        "                            <a href=web-user-product.html?id=" + data.product_List[i].recProductID + "><img style='width: 300px;height: 200px;' src='upload/" + data.product_List[i].recProductImage + "' alt=\"Product\"></a>\n" +
                        "                        </div>\n" +
                        "                        <div class=\"item-content\">\n" +
                        "                            <h3 class=\"item-title\"><a href=web-user-product.html?id=" + data.product_List[i].recProductID + ">" + data.product_List[i].recProductName + "</a>\n" +
                        "                            </h3>\n" +
                        "                            <ul class=\"entry-meta\">\n" +
                        "                                <li><i class=\"far fa-clock\"></i>" + data.product_List[i].recStyleEntity.recStyName + "</li>\n" +
                        "                                <li><i class=\"fas fa-map-marker-alt\"></i>" + data.product_List[i].companyEntity.compAddress + "</li>\n" +
                        "                            </ul>\n" +
                        "                            <div class=\"item-price\">\n" +
                        "                                <span class=\"currency-symbol\">$</span>\n" +
                        "                               " + data.product_List[i].recProductPrice + "<span>/</span>\n" +
                        "                               " + data.product_List[i].recProductUnit + " \n" +
                        "                            </div>\n" +
                        "                        </div>\n" +
                        "                    </div>\n" +
                        "                </div>";
                }
                $("#loadWebList").append(code);
            }
        }
    });
}

//废品公司初始数据
function loadWebList_1() {
    startingPage = 0;
    var data = {
        "page": startingPage,
        "number": number_1
    };
    $.ajax({
        url: "findCompanyByCompanyListAndCompState",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(data),
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            var code = ' ';
            if (data.code == 500) {
                Swal.fire("提示", "查询数据失败", "error");
            } else {
                for (var i = 0; i < data.company_List.length; i++) {
                    if (i < 2) {
                        code += " <div class=\"col-md-3\">\n" +
                            "                    <div class=\"location-box-layout1\">\n" +
                            "                        <a href=web-user-company.html?id=" + data.company_List[i].compID + ">\n" +
                            "                            <div class=" + data.company_List[i].compID + ">\n" +
                            "                                <img style='width: 300px;height: 200px;' src='upload/" + data.company_List[i].compPhoto + "' alt=\"Brooklyn\">\n" +
                            "                            </div>\n" +
                            "                            <div class=\"item-content\">\n" +
                            "                                <h3 class=\"item-title\">" + data.company_List[i].compName + "</h3>\n" +
                            "                                <div class=\"item-count\">" + data.company_List[i].compPhone + "</div>\n" +
                            "                            </div>\n" +
                            "                        </a>\n" +
                            "                    </div>\n" +
                            "                </div>";
                    } else {
                        code += " <div class=\"col-md-6\">\n" +
                            "                    <div class=\"location-box-layout1\">\n" +
                            "                        <a href=\"#\">\n" +
                            "                            <div class=" + data.company_List[i].compID + ">\n" +
                            "                                <img style='width: 600px;height: 400px;' src='upload/" + data.company_List[i].compPhoto + "' alt=\"Brooklyn\">\n" +
                            "                            </div>\n" +
                            "                            <div class=\"item-content\">\n" +
                            "                                <h3 class=\"item-title\">" + data.company_List[i].compName + "</h3>\n" +
                            "                                <div class=\"item-count\">" + data.company_List[i].compPhone + "</div>\n" +
                            "                            </div>\n" +
                            "                        </a>\n" +
                            "                    </div>\n" +
                            "                </div>";
                    }
                }
                $("#loadWebList_1").append(code);
            }
        }
    });
}


$(function () {
    var DATA = '';
    $.ajax({
        url: "JudgeLogin_3",
        type: "POST",
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            if (data.code == 500) {
                DATA += " <li class=\"header-btn\">\n" +
                    "                                    <a href=\"web-login.html\" class=\"item-btn\"><i class=\"fas fa-plus\"></i>登录</a>\n" +
                    "                                </li>"
                Swal.fire("温馨提示", "请先登录", "warning");
                window.location.href = "web-user-404.html";
            } else {
                DATA += " <li class=\"header-login-icon\">\n" +
                    "                                    <a href=\"web-user-account.html\" class=\"color-light\" data-toggle=\"tooltip\"\n" +
                    "                                       data-placement=\"top\" title=\"Login/Register\">\n" +
                    "                                        <i class=\"far fa-user\">我的</i>\n" +
                    "                                    </a>\n" +
                    "                                </li>\n" +
                    "                                <li class=\"header-btn\">\n" +
                    "                                    <a  onclick='tuichu_1()' class=\"item-btn\"><i class=\"fas fa-plus\"></i>退出</a>\n" +
                    "                                </li>";
            }
            $("#userData").html("");
            $("#userData").append(DATA);
        }
    });

    loadWebList();
    loadWebList_1();
})